package friendsearch;

public class GlobalDistance {

	public static double distance(Coordinate p,Coordinate q) {
		double proj;
		proj=Math.cos(p.latitude/180*Math.PI);
		double px=Math.cos(p.longitude/180*Math.PI)*proj;
		double py=Math.sin(p.longitude/180*Math.PI)*proj;
		double pz=Math.sin(p.latitude/180*Math.PI);
		
		proj=Math.cos(q.latitude/180*Math.PI);
		double qx=Math.cos(q.longitude/180*Math.PI)*proj;
		double qy=Math.sin(q.longitude/180*Math.PI)*proj;
		double qz=Math.sin(q.latitude/180*Math.PI);	
		double cosx=(2-((qx-px)*(qx-px)+(qy-py)*(qy-py)+(qz-pz)*(qz-pz)))/2;
		return Math.acos(cosx)*20000/Math.PI;
	}
	
	public static void main(String argv[]) {
	    Coordinate p=new Coordinate(2.0,49.0);
	    Coordinate q=new Coordinate(116.0,40.0);
	    double d=distance(p,q);
	    System.out.println(d);
	}
}
